package test.resource

import com.google.inject.Singleton
import java.util.concurrent.CompletableFuture
import java.util.concurrent.CompletionStage
import org.dataloader.MappedBatchLoader
import org.dataloader.MappedBatchPublisher
import org.reactivestreams.Subscriber
import reactor.core.publisher.Flux

@Singleton
class TestMappedBatchLoader : MappedBatchLoader<String, String> {
  override fun load(keys: Set<String>): CompletionStage<Map<String, String>> {
    println(keys)
    return CompletableFuture.completedFuture(mapOf())
  }
}

@Singleton
class TestMappedBatchPublisher : MappedBatchPublisher<String, String> {
  override fun load(keys: Set<String>, subscriber: Subscriber<Map.Entry<String, String>>) {
    Flux.fromIterable(keys).map { java.util.Map.entry(it, it) }.subscribe(subscriber)
  }
}
